package cn.kkdlk.dxf;

import cn.kkdlk.generate.dxf.DxfDocWriter;
import cn.kkdlk.generate.dxf.Vector3;
import cn.kkdlk.generate.dxf.model.*;
import cn.kkdlk.generate.dxf.model.base.Color;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;


/**
 * @Author ytzjj
 * @DateTime 2023/11/27 16:44
 * @Description 生成dxf
 */
public class GemerateDxf {

    String url = "E:\\test\\测试cad.dxf";

    @Test
    public void testWrite() {
        DxfDocWriter dxfDocWriter = new DxfDocWriter();

        // 创建点
        for (int i = 0; i < 50; i++) {
            DxfPoint dxfPoint = new DxfPoint();
            dxfPoint.setPoint(new Vector3(300 + i, 300.0 + i, 300.0));
            dxfPoint.setColor(Color.fromRGBA(20, 44, 66, 1));
            dxfPoint.setLayerName("点图层");
            dxfDocWriter.addEntity(dxfPoint);
        }


        // 创建多段线实体
        DxfLwPolyLine dxfLwPolyLine = new DxfLwPolyLine();
        List<Vector3> points = new ArrayList<>();
        points.add(new Vector3(100, 100, 100));
        points.add(new Vector3(1000, 1000, 1000));
        points.add(new Vector3(1100, 3000, 2500));
        dxfLwPolyLine.addPoints(points);
        dxfLwPolyLine.setClose(true);
        dxfLwPolyLine.setSolid(true); //是否填充
        dxfLwPolyLine.setSolidColor(Color.PINK); //填充颜色
        dxfLwPolyLine.setColor(Color.BLUE); // 图形颜色
        dxfLwPolyLine.setLayerName("图层111");
        dxfDocWriter.addEntity(dxfLwPolyLine);


        // 创建圆弧
        DxfArc dxfArc = new DxfArc();
        dxfArc.setColor(Color.RED);
        dxfArc.setStartAngle(10);
        dxfArc.setEndAngle(160.0);
        dxfArc.setCenter(new Vector3(200.0, 100.0, 0.0));
        dxfArc.setRadius(200);
        dxfArc.setLayerName("图层222");
        dxfDocWriter.addEntity(dxfArc);

        // 创建圆
        DxfCircle dxfCircle = new DxfCircle();

        dxfCircle.setColor(Color.PINK);
        dxfCircle.setCenter(new Vector3(100.00, 100.00, 0.0));
        dxfCircle.setRadius(100);
        dxfCircle.setSolid(true);
        dxfCircle.setSolidColor(Color.PINK);
        dxfCircle.setLayerName("图层333");
        dxfDocWriter.addEntity(dxfCircle);



        // 创建文本
        DxfText dxfText = new DxfText();

        dxfText.setStartPoint(new Vector3(100, 200, 300));
        dxfText.setText("1234");
        dxfText.setColor(Color.RED);
        dxfText.setCapHeight(30);

        dxfDocWriter.addEntity(dxfText);

        // 创建椭圆
        DxfEllipse dxfEllipse = new DxfEllipse();
        dxfEllipse.setClose(true);
        dxfEllipse.setColor(Color.GRAY);
        dxfEllipse.setSolid(true);
        dxfEllipse.setSolidColor(Color.GRAY);
        dxfEllipse.setCenterPoint(new Vector3(200, 200, 0));
        dxfEllipse.setMajorAxisPoint(new Vector3(600, 200, 0));
        dxfEllipse.setShortAxisScale(0.5);
        dxfDocWriter.addEntity(dxfEllipse);

        // 创建线段
        DxfLine dxfLine = new DxfLine();
        dxfLine.setStartPoint(new Vector3(1000, 1000, 0));
        dxfLine.setEndPoint(new Vector3(2000, 2000, 0));
        dxfLine.setColor(Color.GREEN);
        dxfDocWriter.addEntity(dxfLine);

        // 创建射线
        DxfRay dxfRay = new DxfRay();
        dxfRay.setStart(new Vector3(-100, -100, 0));
        dxfRay.setDirection(new Vector3(-200, -200, 0));
        dxfRay.setColor(Color.BLUE);
        dxfDocWriter.addEntity(dxfRay);

        dxfDocWriter.save(url, true);
    }



    @Test
    public void testPoyLine() {
        DxfDocWriter dxfDocWriter = new DxfDocWriter();


        DxfLwPolyLine dxfLwPolyLine = new DxfLwPolyLine();
        List<Vector3> points = new ArrayList<>();
        points.add(new Vector3(100, 100, 100));
        points.add(new Vector3(1000, 1000, 1000));
        points.add(new Vector3(1100, 3000, 2500));
        dxfLwPolyLine.addPoints(points);
        dxfLwPolyLine.setClose(true);
        dxfLwPolyLine.setSolid(true); //是否填充
        dxfLwPolyLine.setColor(Color.BLUE); // 图形颜色
        dxfLwPolyLine.setSolidColor(Color.colorStringToHex("rgba(134,145,248,0.5)")); //填充颜色
        dxfLwPolyLine.setLayerName("图层111");
        dxfDocWriter.addEntity(dxfLwPolyLine);
        dxfDocWriter.save(url, true);
    }
}
